﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace QuanLyDuocPham.View.QuanLyCauHinh.NguoiDung
{
    /// <summary>
    /// Interaction logic for USER_Add_View.xaml
    /// </summary>
    public partial class USER_Add_View : Window
    {
        public USER_Add_View()
        {
            InitializeComponent();
        }
        public delegate void added();
        public added done;
        Controllers.QuanLyCauHinh.NguoiDung.USER_Control userctrl = new Controllers.QuanLyCauHinh.NguoiDung.USER_Control();
        private void btOk_Click(object sender, RoutedEventArgs e)
        {
            userctrl.addData(cmbHo_Ten, txtTen_DN, txtMat_Khau, cmbNhomND, chbTRANG_THAI);

            if (done != null)
            {
                done();
            }
            
        }

        private void btBack_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
        Controllers.QuanLyCauHinh.NguoiDung.NHOMND_Control nhomndctrl = new Controllers.QuanLyCauHinh.NguoiDung.NHOMND_Control();
        Controllers.QuanLyHeThong.DanhMuc.NHANVIEN_Control nhanvienctrl = new Controllers.QuanLyHeThong.DanhMuc.NHANVIEN_Control();
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            nhomndctrl.loadComboBox(cmbNhomND);
            nhanvienctrl.loadComboBoxU(cmbHo_Ten);
            if (cmbHo_Ten.Items.Count == 0)
            {
                MessageBox.Show("Tất cả nhân viên đều đã được cấp tài khoản!");
                this.Close();
            }
        }

        private void cmbNhomND_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var a = (NHOMND_Get_ListResult)cmbNhomND.SelectedItem;
            if (a != null && a.DIEN_GIAI == "Thêm mới")
            {
                View.QuanLyCauHinh.NguoiDung.NHOMND_Add_View nhomndview = new View.QuanLyCauHinh.NguoiDung.NHOMND_Add_View();
                nhomndview.ShowDialog();
                nhomndctrl.loadComboBox(cmbNhomND);
            }
        }

        private void cmbHo_Ten_KeyDown(object sender, KeyEventArgs e)
        {
            cmbHo_Ten.IsDropDownOpen = true;
        }

        private void cmbNhomND_KeyDown(object sender, KeyEventArgs e)
        {
            cmbNhomND.IsDropDownOpen = true;
        }

        




    }
}
